package com.oragraph.data.group.impl;

import java.util.Vector;

import com.oragraph.data.Node;
import com.oragraph.data.Properties;
import com.oragraph.data.group.Group;
import com.oragraph.data.group.GroupFactory;
import com.oragraph.data.group.GroupTypeManager;

public class BasicGroup implements Group {
	
	private Properties _mutableProperties;
	private Properties _immutableProperties;
	
	private Vector<Node> _children;
	private GroupFactory _groupFactory;
	
	public BasicGroup(String ID, String type) {
		_mutableProperties=new Properties();
		_mutableProperties.setOwner(this);
		_immutableProperties=new Properties();
		_immutableProperties.setOwner(this);
		
		_immutableProperties.set("ID", ID);
		_immutableProperties.set("type", type);
		
		_mutableProperties.set("name", type);
		_mutableProperties.set("filter", "");
		_mutableProperties.set("comment", "");
	}

	@Override
	public Properties getImmutableProperties() {
		return _immutableProperties;
	}

	@Override
	public Properties getMutableProperties() {
		return _mutableProperties;
	}

	@Override
	public String getLabel() {
		int childrenCount=getChildren().size();	
		String filterString="";
		if (!_mutableProperties.get("filter").equals("")) {
			filterString=" FILTERED";
		}
		return _mutableProperties.get("name")+" ["+childrenCount+"]"+filterString;
	}

	@Override
	public String getType() {
		return _immutableProperties.get("type");
	}

	@Override
	public Vector<Node> getChildren() {
		if (_children==null) {
			_children=_groupFactory.getMyChildren(this);
		}
		return _children;
	}

	@Override
	public void reset() {
		_children=null;
	}

	@Override
	public void setGroupFactory(GroupFactory groupFactory) {
		_groupFactory=groupFactory;		
	}
	
	public String toString() {
		return getLabel();
	}
}
